package com.api.shopapi.mapper;

import com.api.shopapi.entity.OrderXiaole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface OrderXiaoleMapper {


    @Insert("insert into order_xiaole (OrderXiaoleCode,"+
            "UserCode,"+
            "ReceiveName,"+
            "ReceivePhone,"+
            "ReceiveArea,"+
            "ReceiveAreaPath,"+
            "ServeClassCode,"+
            "GovernmentCode,"+
            "ReceiveAddress,"+
            "Status,"+
            "CreateTime) values " +
            "(#{orderXiaole.OrderXiaoleCode},"+
            "#{orderXiaole.UserCode},"+
            "#{orderXiaole.ReceiveName},"+
            "#{orderXiaole.ReceivePhone},"+
            "#{orderXiaole.ReceiveArea},"+
            "#{orderXiaole.ReceiveAreaPath},"+
            "#{orderXiaole.ServeClassCode},"+
            "#{orderXiaole.GovernmentCode},"+
            "#{orderXiaole.ReceiveAddress},"+
            "#{orderXiaole.Status},"+
            "#{orderXiaole.CreateTime})")
    int insert(@Param("orderXiaole") OrderXiaole orderXiaole);

    @Update("update order_xiaole set " +
            "UserCode=#{orderXiaole.UserCode} ," +
            "ReceiveName=#{orderXiaole.ReceiveName} ," +
            "ReceivePhone=#{orderXiaole.ReceivePhone} ," +
            "ReceiveArea=#{orderXiaole.ReceiveArea} ," +
            "ReceiveAreaPath=#{orderXiaole.ReceiveAreaPath} ," +
            "ServeClassCode=#{orderXiaole.ServeClassCode} ," +
            "GovernmentCode=#{orderXiaole.GovernmentCode} ," +
            "ReceiveAddress=#{orderXiaole.ReceiveAddress}, " +
            "Status=#{orderXiaole.Status}  " +
            "where OrderXiaoleCode=#{orderXiaole.OrderXiaoleCode}")
    int update(@Param("orderXiaole") OrderXiaole orderXiaole);

    @Delete("delete from order_xiaole where OrderXiaoleCode=#{orderXiaoleCode}")
    int delete(@Param("orderXiaoleCode") String orderXiaoleCode);

    @Select("select * from order_xiaole where OrderXiaoleCode=#{orderXiaoleCode} limit 1")
    OrderXiaole getByOrderXiaoleCode(@Param("orderXiaoleCode") String orderXiaoleCode);

    @Select("select * from order_xiaole where UserCode=#{userCode} and ServeClassCode=#{serveClassCode} and CreateTime >= now()-interval 5 minute")
    List<OrderXiaole> getByTimeAndCode(@Param("userCode") String userCode,@Param("serveClassCode") String serveClassCode);

    @Select("<script>" +
            "select * from order_xiaole where GovernmentCode=#{governmentCode} "+
            "order by CreateTime desc" +
            "</script>")
    List<OrderXiaole> getPageList(@Param("governmentCode") String governmentCode);
}
